I’m gonna look at the NYC restaurant inspection data, specifically Asian restaurants in Manhattan.
library(tidyverse)
library(p8105.datasets)
library(plotly)
I’m gonna work with the NYC restaurant inspection dataset.
data("rest_inspec")
nyc_inspect =
rest_inspec %>%
select(boro, cuisine_description, dba, score, violation_description, grade, building) %>%
filter(grade %in% c("A", "B", "C"))
nyc_inspect %>%
filter(cuisine_description == c("Korean", "Thai", "Chinese", "Vietnamese", "Japanese", "Russian", "Italy", "French", "American", "Mexican")) %>%
mutate(text_label = str_c("Restaurant: ", dba, "\nScore: ", score)) %>%
plot_ly(y = ~score, x = ~cuisine_description,
color = ~cuisine_description, colors = "viridis",
text = ~text_label,
type = "box") %>%
layout(
title = "Scores of restaurants in NY grouped by cuisine",
xaxis = list(title = "Cuisine"),
yaxis = list(title = "Inspection score"))
## Warning in cuisine_description == c("Korean", "Thai", "Chinese", "Vietnamese", :
## longer object length is not a multiple of shorter object length
nyc_inspect %>%
filter(cuisine_description == c("Korean", "Thai", "French", "Pizza", "Italian", "Peruvian", "Geek", "Chinese", "Vietnamese", "Japanese", "Bakery", "Russian", "German", "Indian", "Delicatessen", "Café/Coffee/Tea", "Mexican", "American")) %>%
count(cuisine_description) %>%
mutate(cuisine_description = fct_reorder(cuisine_description, n)) %>%
plot_ly(x = ~cuisine_description, y = ~n, color = ~cuisine_description,
type = "bar", colors = "viridis") %>%
layout(
title = "Count of restaurants in Manhattan by cuisine",
xaxis = list(title = "Cuisine"),
yaxis = list(title = "Count"))
## Warning in cuisine_description == c("Korean", "Thai", "French", "Pizza", :
## longer object length is not a multiple of shorter object length
nyc_inspect %>%
filter(cuisine_description == c("Korean", "Thai", "Chinese", "Vietnamese", "Japanese", "Russian", "Italy", "French", "American", "Mexican")) %>%
filter(score %in% 20:50) %>%
mutate(text_label = str_c("Score: ", score)) %>%
plot_ly(x = ~cuisine_description, y = ~dba,
type = "scatter", mode = "markers", text = ~text_label,
color = ~score, colors = "viridis") %>%
layout(title = "Restaurants with score between 20 and 50",
xaxis = list(title = "Cuisine"),
yaxis = list(title = "Restaurant"))
## Warning in cuisine_description == c("Korean", "Thai", "Chinese", "Vietnamese", :
## longer object length is not a multiple of shorter object length
nyc_inspect %>%
mutate(text_label = str_c("Restaurant: ", dba, "\nScore: ", score)) %>%
plot_ly(x = ~score, type = "histogram", color = "orange", alpha = .8, text = ~text_label) %>%
layout(title = "Histogram of inspection scores of NY restaurants",
xaxis = list(title = "Score"),
yaxis = list(title = "Count"))
## Warning: Ignoring 3 observations
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels